package cn.xuqiudong.rpc.demo.consumer.controller;

import cn.xuqiudong.rpc.demo.common.model.OneModel;
import cn.xuqiudong.rpc.demo.consumer.service.ConsumerService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 描述:
 * @author Vic.xu
 * @date 2022-03-01 17:46
 */
@RestController
public class ConsumerController {

    @Resource
    private ConsumerService consumerService;

    /**
     * 测试列表
     * @param num
     * @return
     */
    @GetMapping("/list")
    public List<OneModel> list(@RequestParam(defaultValue = "10") int num){

        return consumerService.list(num);
    }

    @GetMapping("/detail")
    public OneModel findId(@RequestParam(defaultValue = "12") int id){
        return consumerService.detail(id);
    }

    @GetMapping("/search")
    public OneModel search(@RequestParam(defaultValue = "张三") String name){
        return consumerService.search(name);
    }


    @GetMapping("/from")
    public Map<String,Object> from(@RequestParam(defaultValue = "张三") String name){
        Map<String,Object> result = new HashMap<>();
        for (int i = 0; i < 10; i++) {
            result.put("第" + (i +1) + "次",consumerService.from(name));
        }
        return result;

    }
}
